<?php
class Analisa_model extends Model{
	
	function analisa_model(){
		parent::Model();
	}
	
	function ana_off(){
		$this->truncate();
		$an_des = array('id_p1' => '',
						'id_p2' => '',
						'id_p3' => '',
						'id_p4' => '',
						'id_p5' => '',
						'p1' => '',
						'p2' => '',
						'p3' => '',
						'p4' => '',
						'p5' => '',
						'jml_per' => '',
						'n_tabel' => '');
		$this->session->unset_userdata($an_des);
		$this->session->set_userdata('analisa', FALSE);
	}
	
	function simpan($n_tabel, $data){
		$this->db->insert($n_tabel, $data);
	}
	
	function get_max(){
		$id_la = 0;
		$this->db->select_max('ID_simpan','max_id');
		$has = $this->db->get('simpan_semen');
		foreach($has->result() as $ha){
			$id_la = $ha->max_id;
		}
		return $id_la;
	}
	
	function update($id, $data){
		$this->db->where('ID_simpan', $id);
		$this->db->update('simpan_semen', $data);
	}
	
	function select_per($n_kolom, $no){
		$this->db->select($n_kolom);
		$this->db->where('no', $no);
		$has = $this->db->get('jenis_periode');
		foreach($has->result_array() as $row){
			$hasil = $row[$n_kolom];
		}
		return $hasil;
	}
	
	function baca_semen($n_var, $id){
		$this->db->where('ID_simpan', $id);
		$this->db->select($n_var);
		$has = $this->db->get('simpan_semen');
		foreach($has->result_array() as $row){
			$hasil = $row[$n_var];
		}
		return $hasil;
	}
	
	function get_arow($id){
		return $this->db->get_where('simpan_semen', array('ID_simpan' => $id))->row();
	}
	
	function truncate(){
		$this->db->truncate('simpan_semen');
	}
	
	function hitung_p1($cadangan, $lalai12){
		$hasil = $cadangan / $lalai12 * 100;
		return $hasil;
	}
	
	function hitung_p2($cadangan, $lalai112){
		$hasil = $cadangan / $lalai112 * 100;
		return $hasil;
	}
	
	function hitung_e1($piutang, $totalaset){
		$hasil = $piutang / $totalaset * 100;
		return $hasil;
	}
	
	function hitung_e2($simpanan_non_saham, $totalaset){
		$hasil = $simpanan_non_saham / $totalaset * 100;
		return $hasil;
	}
	
	function hitung_e3($pinjam_III, $totalaset){
		$hasil = $pinjam_III / $totalaset * 100;
		return $hasil;
	}
	
	function hitung_e4($modal_saham, $totalaset){
		$hasil = $modal_saham / $totalaset * 100;
		return $hasil;
	}
	
	function hitung_e5($modal_lembaga, $totalaset){
		$hasil = $modal_lembaga / $totalaset * 100;
		return $hasil;
	}
	
	function hitung_a1($macet_pasiva, $total_piutang){
		$hasil = $macet_pasiva / $total_piutang * 100;
		return $hasil;
	}
	
	function hitung_a2($totalaset_tak_hasil, $totalaset){
		$hasil = $totalaset_tak_hasil / $totalaset * 100;
		return $hasil;
	}
	
	function hitung_a3($modal_lember, $modal_transit, $hutang_tak_berbunga, $aset_tak_menghas){
		$hasil = ($modal_lember + $modal_transit + $hutang_tak_berbunga) / $aset_tak_menghas * 100;
		return $hasil;
	}
	
	function hitung_r1($total_biaya_ops, $total_penda_ops){
		$hasil = $total_biaya_ops / $total_penda_ops * 100;
		return $hasil;
	}
	
	function hitung_r2($laba_bersih, $modalsaham){
		$hasil = $laba_bersih / $modalsaham * 100;
		return $hasil;
	}
	
	function hitung_r3($laba_bersih, $aset_rata2){
		$hasil = $laba_bersih / $aset_rata2 * 100;
		return $hasil;
	}
	
	function hitung_l1($kas, $ABA, $ABP, $simpanan_non_saham){
		$hasil = ($kas + $ABA - $ABP) / $simpanan_non_saham * 100;
		return $hasil;
	}
	
	function hitung_l2($kredit_diberikan, $simpanan_non_saham){
		$hasil = $kredit_diberikan / $simpanan_non_saham * 100;
		return $hasil;
	}
	
	function hitung_l3($aset_likuid_tdkmnghasilkan, $total_aset){
		$hasil = $aset_likuid_tdkmnghasilkan / $total_aset * 100;
		return $hasil;
	}
	
	function hitung_s1($jmlh_piutang_jalan_anggota, $jmlh_piutang_lalu_anggota){
		$hasil = (($jmlh_piutang_jalan_anggota - $jmlh_piutang_lalu_anggota) / $jmlh_piutang_lalu_anggota) * 100; 
		return $hasil;
	}
	
	function hitung_s2($jmlah_simpanan_non_jalan, $jmlah_simpanan_lalu){
		$hasil = (($jmlah_simpanan_non_jalan - $jmlah_simpanan_lalu) / $jmlah_simpanan_lalu) * 100;
		return $hasil;
	}
	
	function hitung_s3($Jmlah_cdangan_modal_jalan, $jmlah_cdangan_modal_lalu){
		$hasil = (($Jmlah_cdangan_modal_jalan - $jmlah_cdangan_modal_lalu) / $jmlah_cdangan_modal_lalu) * 100;
		return $hasil;
	}
	
	function hitung_s4($jmlah_modal_lem_jalan, $jmlah_moda_lem_lalu){
		$hasil = (($jmlah_modal_lem_jalan - $jmlah_moda_lem_lalu) / $jmlah_moda_lem_lalu) * 100;
		return $hasil;
	}
	
	function hitung_s5($jmlah_outlet_jalan, $jmlah_outlet_lalu){
		$hasil = (($jmlah_outlet_jalan - $jmlah_outlet_lalu) / $jmlah_outlet_lalu) * 100;
		return $hasil;
	}
	
	function hitung_s6($jmlah_anggota_jalan, $jmlah_anggota_lalu){
		$hasil = (($jmlah_anggota_jalan - $jmlah_anggota_lalu) / $jmlah_anggota_lalu) * 100;
		return $hasil;
	}
	
	function hitung_s7($jmlah_aset_jalan, $jmlah_aset_lalu){
		$hasil = (($jmlah_aset_jalan - $jmlah_aset_lalu) / $jmlah_aset_lalu) * 100;
		return $hasil;
	}
	
	function nilai_p1($nilai){
		if($nilai < 100){
			$hasil = 40;
		}
		if($nilai = 100){
			$hasil = 60;
		}
		if($nilai > 100){
			$hasil = 80;
		}
		return $hasil;
	}
	
	function nilai_p2($nilai){
		if($nilai < 35){
			$hasil = 40;
		}
		if($nilai = 35){
			$hasil = 60;
		}
		if($nilai > 35){
			$hasil = 80;
		}
		return $hasil;
	}
	
	function nilai_e1($nilai){
		if($nilai > 80){
			$hasil = 40;
		}
		if($nilai >= 70 && $nilai <= 80){
			$hasil = 60;
		}
		if($nilai < 70){
			$hasil = 80;
		}
		return $hasil;
	}
	
	function nilai_e2($nilai){
		if($nilai < 70){
			$hasil = 40;
		}
		if($nilai >= 70 && $nilai <= 80){
			$hasil = 60;
		}
		if($nilai > 80){
			$hasil = 80;
		}
		return $hasil;
	}
	
	function nilai_e3($nilai){
		if($nilai > 10){
			$hasil = 40;
		}
		if($nilai = 10){
			$hasil = 60;
		}
		if($nilai < 10){
			$hasil = 80;
		}
		return $hasil;
	}
	
	function nilai_e4($nilai){
		if($nilai < 10){
			$hasil = 40;
		}
		if($nilai >= 10 && $nilai <= 20){
			$hasil = 60;
		}
		if($nilai > 20){
			$hasil = 80;
		}
		return $hasil;
	}
	
	function nilai_e5($nilai){
		if($nilai < 10){
			$hasil = 40;
		}
		if($nilai = 10){
			$hasil = 60;
		}
		if($nilai > 10){
			$hasil = 80;
		}
		return $hasil;
	}
	
	function nilai_a1($nilai){
		if($nilai > 3){
			$hasil = 40;
		}
		if($nilai <= 3){
			$hasil = 80;
		}
		return $hasil;
	}
	
	function nilai_a2($nilai){
		if($nilai > 3){
			$hasil = 40;
		}
		if($nilai <= 3){
			$hasil = 80;
		}
		return $hasil;
	}
	
	function nilai_a3($nilai){
		if($nilai < 200){
			$hasil = 40;
		}
		if($nilai = 200){
			$hasil = 60;
		}
		if($nilai > 200){
			$hasil = 80;
		}
		return $hasil;
	}
	
	function nilai_r1($nilai){
		if($nilai > 80){
			$hasil = 40;
		}
		if($nilai = 80){
			$hasil = 60;
		}
		if($nilai < 80){
			$hasil = 80;
		}
		return $hasil;
	}
	
	function nilai_r2($nilai){
		if($nilai < 10){
			$hasil = 40;
		}
		if($nilai = 10){
			$hasil = 60;
		}
		if($nilai > 10){
			$hasil = 80;
		}
		return $hasil;
	}
	
	function nilai_r3($nilai){
		if($nilai < 3){
			$hasil = 40;
		}
		if($nilai = 3){
			$hasil = 60;
		}
		if($nilai > 3){
			$hasil = 80;
		}
		return $hasil;
	}
	
	function nilai_l1($nilai){
		if($nilai > 20){
			$hasil = 40;
		}
		if($nilai >= 15 && $nilai <= 20){
			$hasil = 60;
		}
		if($nilai < 15){
			$hasil = 80;
		}
		return $hasil;
	}
	
	function nilai_l2($nilai){
		if($nilai < 85 && $nilai > 100){
			$hasil = 40;
		}
		if($nilai = 85){
			$hasil = 60;
		}
		if($nilai > 85 && $nilai < 100){
			$hasil = 80;
		}
		return $hasil;
	}
	
	function nilai_l3($nilai){
		if($nilai > 1){
			$hasil = 40;
		}
		if($nilai = 1){
			$hasil = 60;
		}
		if($nilai < 1){
			$hasil = 80;
		}
		return $hasil;
	}
	
	function nilai_s1($nilai){
		if($nilai < 25){
			$hasil = 40;
		}
		if($nilai = 25){
			$hasil = 60;
		}
		if($nilai > 25){
			$hasil = 80;
		}
		return $hasil;
	}
	
	function nilai_s2($nilai){
		if($nilai < 20){
			$hasil = 40;
		}
		if($nilai = 20){
			$hasil = 60;
		}
		if($nilai > 20){
			$hasil = 80;
		}
		return $hasil;
	}
	
	function nilai_s3($nilai){
		if($nilai < 20){
			$hasil = 40;
		}
		if($nilai = 20){
			$hasil = 60;
		}
		if($nilai > 20){
			$hasil = 80;
		}
		return $hasil;
	}
	
	function nilai_s4($nilai){
		if($nilai < 50){
			$hasil = 40;
		}
		if($nilai = 50){
			$hasil = 60;
		}
		if($nilai > 50){
			$hasil = 80;
		}
		return $hasil;
	}
	
	function nilai_s5($nilai){
		if($nilai < 25){
			$hasil = 40;
		}
		if($nilai = 25){
			$hasil = 60;
		}
		if($nilai > 25){
			$hasil = 80;
		}
		return $hasil;
	}
	
	function nilai_s6($nilai){
		if($nilai < 50){
			$hasil = 40;
		}
		if($nilai = 50){
			$hasil = 60;
		}
		if($nilai > 50){
			$hasil = 80;
		}
		return $hasil;
	}
	
	function nilai_s7($nilai){
		if($nilai < 30){
			$hasil = 40;
		}
		if($nilai = 30){
			$hasil = 60;
		}
		if($nilai > 30){
			$hasil = 80;
		}
		return $hasil;
	}
}
?>